require(['./config'],()=>{
require(['jquery','header',],(jquery)=>{
      class Register{
          constructor(){
            this.init()
          }
          init(){      
            let trs2 =false
           $('.username').on('blur',function(){//账户
            let flag = false;
            let tem =  $('.username').val()
            let reg = /^[\u4e00-\u9fa5a-zA-Z0-9_]+$/;
            console.log(reg.test(tem));
            trs2 = reg.test(tem)
            if (reg.test(tem)) {
                let res = tem.replace(/[\u4e00-\u9fa5]/g, 'aa').length;
                
                res > 14 ? flag = false : flag = true;
            }
            if (flag) {
                $('.hint').html('欢迎您尊敬的客户').css({
                    "color":"red", 
                    "font-size":"12px",           
                    })
            } else {
                $('.hint').html('用户名不正确或用户已存在,请重新输入...').css('color','red')
            } 
            
           })
        //结束
        let trs3=false
           $('.password').on('blur',function(){//密码
            let pasag = false;
            let tem1 =  $('.password').val()
                // >长度为8-14位字符，支持数字，大小写字母和标点符号，不允许有空格
                let reg = /^\S{8,14}$/i;
                trs3 = reg.test(tem1);
                console.log(trs3);
                
                if (trs3 == false) {
                    $('.spans').html( '你输入的长度未满住条件请确保长度至少为8-14位数字').css({
                        "color":"red", 
                        "font-size":"12px",           
                        }) 
                   
                } else {
                    $('.spans').html('安全系数正确').css({
                        "color":"red", 
                        "font-size":"12px",           
                        }) 
                }
           })
            // 结束 
             //点击注册  
                $('.register').on('click',()=>{
                    const username = $('.username').val()
                    const password = $('.password').val()
                    const userinfo = {username,password}//那个变量存起来
                    let users = localStorage.getItem('users') //取
                //如果里面没有值
                    if(users){
                    // 如果有那就转为数组类型的方便注册多条
                    users = JSON.parse(users)
                    users.push(userinfo)
                    localStorage.setItem('users',JSON.stringify(users))
                    if(trs2&&trs3){
                        function tiaozU(){ //这里是需要的
                          window.location.href='/html/login.html'
                        }
                     setTimeout(tiaozU,500)
                     alert('注册成功')          
                    }
                    }else{
                    // 如果没有
                    const arr = [userinfo]
                    // 弄进数组在存
                    localStorage.setItem('users',JSON.stringify(arr))       
                    }
                    
               
            })

          }
      }
    new Register
})
})